<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ include file="/taglibs.jsp"%>
<%@taglib uri="/WEB-INF/tld/pageutil.tld" prefix="pu"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@page import="com.yaodian100.core.common.utils.ServerValue"%>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath()%>'/>
<!-- 地址选单 -->
<script type="text/javascript" charset="UTF-8" src="/genJS/yaodian_zipcodeMidend.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.cascade.ext.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.cascade.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.templating.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<!-- 验证 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.checkboxes.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/formValidator_min.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/formValidator.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/formValidatorRegex.js"></script>
<!-- 数字验证 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/yaodian100.common.js"></script>
<script src="${midContextPath}/js/jquery.MultiFile.js" type="text/javascript" language="javascript"></script>
<link rel="stylesheet" href="<%=ServerValue.getMidContextPath()%>/css/jquery.tooltip.css" />
<script src="<%=ServerValue.getMidContextPath()%>/js/jquery.tooltip.js" type="text/javascript"></script>

<script language="javascript">
	$().ready( function() {
		set_ddl_date(1911);	
		$.each(provinceArray,function(index, item){
			$("#coprovince").append("<option value='" + item.Value + "'>" + item.Text + "</option>"); //供应商地址		    
		  });
		jQuery("#cocity").cascade("#coprovince",{//供应商地址					
			list : cityArray,				
			template: commonTemplate,
			match: commonMatch 
		});
		
		jQuery("#codistrict").cascade("#cocity",{//供应商地址					
			list: districtArray,
			template: commonTemplate,
			match: commonMatch 
		});
		
			if ( $("#supplierID").val() != "" ){
				$.each(provinceArray,function(index, item){//供应商地址
					if ( item.Value == "${newsupplierapply.companyProvince}" ){
						$("#coprovince").attr("selectedIndex",index+1);
					}
				});
				
				$.each(cityArray,function(index, item){//供应商地址
					if ( item.When == "${newsupplierapply.companyProvince}" ){
						$("#cocity").append("<option value='" + item.Value + "'>" + item.Text + "</option>");
					}
				});

				var newCityArrayCo = jQuery.grep(cityArray, function (item) { return item.When == "${newsupplierapply.companyProvince}"; });//供应商地址
				
				$.each(newCityArrayCo,function(index, item){//供应商地址
					if ( item.Value == "${newsupplierapply.companyCity}" ){
						$("#cocity").attr("selectedIndex",index+1);
					}
				});
				
				$.each(districtArray,function(index, item){//供应商地址
					if ( item.When == "${newsupplierapply.companyCity}" ){
						$("#codistrict").append("<option value='" + item.Value + "'>" + item.Text + "</option>");
					}
				});
				
				
				newDistrictArrayCo = jQuery.grep(districtArray, function (item) { return item.When == "${newsupplierapply.companyCity}"; });//供应商地址
				
				$.each(newDistrictArrayCo,function(index, item){//供应商地址
					if ( item.Value == "${newsupplierapply.companyArea}" ){
						$("#codistrict").attr("selectedIndex",index+1);
					}
				});
			}
			
		$.formValidator.initConfig({
			formid:"formObj",
			onerror:function(msg)
			{alert(msg);},
			onsuccess:function()
			{return true;}
		});
			
		$("#category").formValidator().inputValidator({	
			min:1,
			max:50,
			onerror:"<最希望上架的类别>为必选" 
		});

		$("#taxInvoice").formValidator().inputValidator({	
			min:1,
			max:50,
			onerror:"<纳税人性质／发票性质>为必选" 
		});
	
		$("#companyPhone").formValidator().inputValidator({	
			min:2,
			max:50,
			onerror:"<公司电话>须小于50个字元且为必填" 
		});

		$("#companyFax").formValidator({empty:true}).inputValidator({	
			min:0,
			max:50,
			onerror:"<公司传真>须小于50个字元" 
		});

		$("#contactPhone").formValidator().inputValidator({	
			min:2,
			max:50,
			onerror:"<联络人电话>须小于50个字元且为必填" 
		});
		
		
		$("#cozip").formValidator().inputValidator({	
			min:2,
			max:6,
			onerror:"<邮编>须小于6个字元且为必填" }).regexValidator({
			regexp:"zipcode",datatype:"enum",
			onerror:"<公司地址邮编>格式不对"
		});

		$("#companyAddress").formValidator().inputValidator({	
			min:2,
			max:80,
			onerror:"<公司地址>须小于80个字元且为必填" 
		});
			
		$("#companyName").formValidator().inputValidator({	
			min:1,
			max:80,
			onerror:"<公司名称>须小于80个字元且为必填" 
		});


		$("#ownerName").formValidator({empty:true}).inputValidator({
			min:0,
			max:30,
			onerror:"<负责人姓名>须小于30个字元"
		});

		$("#ownerID").formValidator({empty:true}).inputValidator({
			min:0,
			max:20,
			onerror:"<负责人身分证>须小于20个字元"
		});

		$("#companyabout").formValidator().inputValidator({
			min:0,
			max:80,
			onerror:"<公司简述>须小于40个中文字"
		});

		$("#contactFax").formValidator().inputValidator({
			min:0,
			max:50,
			onerror:"<联络人传真>须小于50个字元"
		});

		$("#contactAddress").formValidator().inputValidator({
			min:0,
			max:80,
			onerror:"<联络人地址>须小于80个字元"
		});

		$("#note").formValidator().inputValidator({
			min:0,
			max:200,
			onerror:"<其它说明>须小于200个字元"
		});
		
		$("#companyNum").formValidator().inputValidator({	
			min:1,
			max:35,
			onerror:"<供应商营业执照注册号>须小于35个字元且为必填" 
		});
	
		$("#companyemployee").formValidator({empty:true}).inputValidator({
			min:0,
			max:10,
			onerror:"<公司人数>须小于10个字元"
		}).regexValidator({
			regexp:"intege1",datatype:"enum",
			onerror:"<公司人数>必须是正整数"
		});
		
		$("#contactName").formValidator().inputValidator({
			min:2,
			max:16,
			onerror:"<联络人姓名>须介于2-16个字元之间且不能为空值"
		});
	
		$("#companycapital").formValidator({empty:true}).regexValidator({
			regexp:"decmal4",datatype:"enum",		
			onerror:"公司资本额必须是正浮点数"
		});

		$("#contactEmail").formValidator().inputValidator({	
			min:2,
			max:100,
			onerror:"<联络人Email>为必填栏位" }).regexValidator({
			regexp:"email",datatype:"enum",
			onerror:"你输入的邮箱格式不正确"
		});

		$("#recommendproduct").formValidator().inputValidator({
			min:2,
			max:200,
			onerror:"<最推荐的强力商品是>须小于200个字元且必填"
		});

		
		$("#saveBtn").click(function() {
			
			if ( $("#coprovince option:selected").val() == "" ){
				alert("<公司地址－省份>为必选");
				$("#coprovince").focus();
				return false;
			}
			if ( $("#cocity option:selected").val() == "" ){
				alert("<公司地址－市>为必选");
				$("#cocity").focus();
				return false;
			}
			if ( $("#codistrict option:selected").val() == "" ){
				alert("<公司地址－区>为必选");
				$("#codistrict").focus();
				return false;
			}


			if($("#esyear").val()!= ""){
				if($("#esmonth").val()==""){
					alert("<公司成立时间>你只選了年份,忘了選月份喔!");
					$("#esmonth").focus();
					return false;
				}
			}

			if($("#esmonth").val()!= ""){
				if($("#esyear").val()==""){
					alert("<公司成立时间>你只選了月份,忘了選年份喔!");
					$("#esyear").focus();
					return false;
				}
			}
			
			if($.trim($("#imageDecription").val())!= ""){
				if($.trim($("#image").val())==""){
					alert("<档案一>有填写档案说明，但却没上传档案喔");
					$("#image").focus();
					return false;
				}
			}
			if($.trim($("#imageDecription1").val())!= ""){
				if($.trim($("#image1").val())==""){
					alert("<档案二>有填写档案说明，但却没上传档案喔");
					$("#image1").focus();
					return false;
				}
			}
			if($.trim($("#imageDecription2").val())!= ""){
				if($.trim($("#image2").val())==""){
					alert("<档案三>有填写档案说明，但却没上传档案喔");
					$("#image2").focus();
					return false;
				}
			}
			if($.trim($("#imageDecription3").val())!= ""){
				if($.trim($("#image3").val())==""){
					alert("<档案四>有填写档案说明，但却没上传档案喔");
					$("#image3").focus();
					return false;
				}
			}
			if($.trim($("#imageDecription4").val())!= ""){
				if($.trim($("#image4").val())==""){
					alert("<档案五>有填写档案说明，但却没上传档案喔");
					$("#image4").focus();
					return false;
				}
			}
			if($.trim($("#image").val())!= ""){
				if($.trim($("#imageDecription").val())==""){
					alert("<档案一的档案说明>不能为空,必须为<档案一>作说明");
					$("#imageDecription").focus();
					return false;
				}
			}
			if($.trim($("#image1").val())!= ""){
				if($.trim($("#imageDecription1").val())==""){
					alert("<档案二的档案说明>不能为空,必须为<档案二>作说明");
					$("#imageDecription1").focus();
					return false;
				}
			}
			if($.trim($("#image2").val())!= ""){
				if($.trim($("#imageDecription2").val())==""){
					alert("<档案三的档案说明>不能为空,必须为<档案三>作说明");
					$("#imageDecription2").focus();
					return false;
				}
			}
			if($.trim($("#image3").val())!= ""){
				if($.trim($("#imageDecription3").val())==""){
					alert("<档案四的档案说明>不能为空,必须为<档案四>作说明");
					$("#imageDecription3").focus();
					return false;
				}
			}
			if($.trim($("#image4").val())!= ""){
				if($.trim($("#imageDecription4").val())==""){
					alert("<档案五的档案说明>不能为空,必须为<档案五>作说明");
					$("#imageDecription4").focus();
					return false;
				}
			}
			
			$('#formObj').submit();			
		});
		
		$("#noPassBtn").click(function() {	
			if(confirm('确定要不通过吗?')){		
				$.post("${midContextPath}/newSupplierApply/reject.do", {supplierID:'${newsupplierapply.supplierID }'}, callbackFun, "json");	
			}
			function callbackFun(saveResult){
				if ( saveResult == "" ){
					alert("审核失败");
				}else{
					alert(saveResult);
					window.location.replace("${midContextPath}/newSupplierApply/view.do?supplierID=${newsupplierapply.supplierID }");
				}
			}
		});

		$("#passBtn").click(function() {	
			if(confirm('确定要核可吗?')){		
				$.post("${midContextPath}/newSupplierApply/st0pass.do", {supplierID:'${newsupplierapply.supplierID }'}, callbackFun, "json");	
			}
			function callbackFun(saveResult){
				if ( saveResult == "" ){
					alert("审核失败");
				}else{
					alert(saveResult);
					window.location.replace("${midContextPath}/newSupplierApply/view.do?supplierID=${newsupplierapply.supplierID }");
				}
			}
		});
	});
	function commonTemplate(item) {
		return "<option value='" + item.Value + "'>" + item.Text + "</option>"; 
	}
	function commonMatch(selectedValue) {
		return this.When == selectedValue; 
	}
	
	function set_ddl_date(year_start){  
		var now = new Date();    
		//年(year_start~今年)  
		for(var i = now.getFullYear(); i >= year_start; i--){ 
		$('#esyear').  
		append($("<option></option>"). 
		attr("value",i).  
		text(i));  
		}   

		//月  
		for(var i = 1; i <= 12; i++){  
		$('#esmonth').  
		append($("<option></option>").  
		attr("value",i).  
		text(i));  
		}
		if("${newsupplierapply.companyesttime}"!=""){
			$("#esyear option[text='${esyear}']").attr("selected", true);   
			$("#esmonth option[text='${esmonth}']").attr("selected", true);  	
		}
	}
</script>
<h1>供应商申请管理</h1>
<div style="height:30px" class="f-link">
	<a href="${midContextPath}/newSupplierApply/search.do">回查询页</a>
</div>
<div style="color:red">
	<s:actionerror />
	<s:actionmessage />
	<s:fielderror />
</div>
<s:form name="formObj" id="formObj" action="save.do" method="post" enctype ="multipart/form-data">
<input type="hidden" name="supplierID" value="${newsupplierapply.supplierID}"/>
<table class="tb-data" width="100%">	
	<tr><th height="35" colspan="2"  align=center ><h4>公司基本资料</h4></th></tr>
	<c:if test="${!empty newsupplierapply.supplierID }">
		<tr>
			<th>供应商申请编号</th>
			<td> ${newsupplierapply.supplierID}</td>
		</tr>
	</c:if>
	<tr>
		<th><span style="color:red">*</span>供应商名称</th>
		<td><s:textfield name="newsupplierapply.companyName" id="companyName" size="50" maxlength="80"/>最多80个字</td>
	</tr>
	<tr>
		<th><span style="color:red">*</span>供应商营业执照注册号</th>
		<td><s:textfield name="newsupplierapply.companyNum" id="companyNum" size="50" maxlength="35"/>最多35个字</td>
	</tr>
	
	<tr>
		<th>负责人姓名</th>
		<td><s:textfield name="newsupplierapply.ownerName" id="ownerName" size="50" maxlength="30"/>最多30个字</td>
	</tr>
	<tr>
		<th>负责人身分证</th>
		<td><s:textfield name="newsupplierapply.ownerID" id="ownerID" size="50" maxlength="20"/>最多20个字</td>
	</tr>
	<tr>
		<th>公司人数</th>
		<td><s:textfield name="newsupplierapply.companyemployee" id="companyemployee" size="10" maxlength="10"/>最多10个字</td>
	</tr>
	<tr>
		<th>公司资本额</th>
		<td><s:textfield name="newsupplierapply.companycapital" id="companycapital" size="10" maxlength="50"/>万元</td>
	</tr>
	<tr>
		<th>公司成立时间</th>
		<td>
			<select name="esyear" id="esyear"><option value="" >年</option></select>
			<select name="esmonth" id="esmonth"><option value="" >月</option></select> 
		</td>
		
	</tr>
	<tr>
		<th><span style="color:red">*</span>纳税人性质／发票性质</th>
		<td><s:select name="newsupplierapply.taxInvoice" id="taxInvoice" list="menuTaxInvoice.options" headerKey="" headerValue="请选择" listKey="key" listValue="value.name"/></td>
	</tr>
	<tr>
		<th><span style="color:red">*</span>公司电话</th>
		<td><s:textfield name="newsupplierapply.companyPhone" id="companyPhone" size="50" maxlength="50"/>最多50个字</td>
	</tr>
	<tr>
		<th>公司传真</th>
		<td><s:textfield name="newsupplierapply.companyFax" id="companyFax" size="50" maxlength="50"/>最多50个字</td>
	</tr>
	<tr>
		<th><span style="color:red">*</span>公司地址</th>
		<td>
		<span style="color:red">*</span>省份：<select id="coprovince" name="newsupplierapply.companyProvince" class="c-prov"><option value="">== 选择省 ==</option></select>
		<span style="color:red">*</span>市：<select id="cocity" name="newsupplierapply.companyCity"><option value="">== 选择城市 ==</option></select>
		<span style="color:red">*</span>区：<select id="codistrict" name="newsupplierapply.companyArea"><option value="">== 选择地区 ==</option></select><br />
		<span style="color:red">*</span>邮编：<s:textfield name="newsupplierapply.companyZip" id="cozip" size="6" maxlength="6"/> 
		　<s:textfield name="newsupplierapply.companyAddress" id="companyAddress" size="80" maxlength="80"/>最多80个字
		</td>
		
	</tr>
	<tr>
		<th>公司网址</th>
		<td><s:textfield name="newsupplierapply.companywebsite" id="companywebsite" size="50"/></td>
	</tr>
	<tr>
		<th>公司简述</th>
		<td><s:textarea name="newsupplierapply.companyabout" id="companyabout" cols="60"/>40个中文字以内</td>
	</tr>
	<tr><th height="35" colspan="2"  align=center ><h4>申请资料</h4></th></tr>
	<tr>
		<th><span style="color:red">*</span>联络人姓名</th>
		<td><s:textfield name="newsupplierapply.contactName" id="contactName" size="50" maxlength="50"/>最多50个字</td>
	</tr>
	<tr>
		<th><span style="color:red">*</span>联络人电话</th>
		<td><s:textfield name="newsupplierapply.contactPhone" id="contactPhone" size="50" maxlength="50"/>最多50个字</td>
	</tr>
	<tr>
		<th>联络人传真</th>
		<td><s:textfield name="newsupplierapply.contactFax" id="contactFax" size="50" maxlength="50"/>最多50个字</td>
	</tr>
	<tr>
		<th>联络人地址</th>
		<td><s:textfield name="newsupplierapply.contactAddress" id="contactAddress" size="50" maxlength="80"/>最多80个字</td>
	</tr>
	<tr>
		<th><span style="color:red">*</span>联络人Email</th>
		<td><s:textfield name="newsupplierapply.contactEmail" id="contactEmail" size="50" maxlength="100"/>最多100个字</td>
	</tr>
	<tr>
		<th><span style="color:red">*</span>最推荐的强力商品是</th>
		<td><s:textarea name="newsupplierapply.recommendproduct" id="recommendproduct" rows="3" cols="60"/>200字内</td>
	</tr>	
	<tr>
		<th>档案上传</th>
		<td>
			<c:if test="${!empty newsupplierapply.supplierID }">
				<c-rt:forEach items="${nasphotoList}" var="photos">
					<a href="/newsupplierapply/${newsupplierapply.supplierID}/${photos.filename}" target="_blank">${photos.filename} 档案说明:${photos.filedecription} </a> <span class="txt-rd">刪除</span><input name="photoDelete" type="checkbox" value="${photos.photoid}"/><br />
				</c-rt:forEach>	
			</c:if>
			
			档案一:<s:file id="image" name="image" value="" size="60"></s:file> 档案说明:<input id="imageDecription" type="text" name="imageDecription" /><br />
			档案二:<s:file id="image1" name="image1" value="" size="60"></s:file> 档案说明:<input id="imageDecription1" type="text" name="imageDecription1" /><br />
			档案三:<s:file id="image2" name="image2" value="" size="60"></s:file> 档案说明:<input id="imageDecription2" type="text" name="imageDecription2" /><br />	
			档案四:<s:file id="image3" name="image3" value="" size="60"></s:file> 档案说明:<input id="imageDecription3" type="text" name="imageDecription3" /><br />
			档案五:<s:file id="image4" name="image4" value="" size="60"></s:file> 档案说明:<input id="imageDecription4" type="text" name="imageDecription4" /><br />
			<span class="txt-rd">(每个档案大小限制1M)</span>
		</td>
	</tr>
	
	<tr>
		<th><span style="color:red">*</span>最希望上架的类别是</th>
		<td>馆
			<s:select list="rootCategories" name="newsupplierapply.category" id="category" headerKey="" headerValue="请选择" listKey="id" listValue="aliasName" />	
		</td>
	</tr>
	<tr>
		<th>附选上架的类别（最多二个）</th>
		<td>馆
			<s:select list="rootCategories" name="newsupplierapply.categoryother1" headerKey="" headerValue="请选择" listKey="id" listValue="aliasName" /><br />		
			馆
			<s:select list="rootCategories" name="newsupplierapply.categoryother2" headerKey="" headerValue="请选择" listKey="id" listValue="aliasName" />	
		</td>
	</tr>
	<tr>
		<th>其它说明</th>
		<td><s:textarea name="newsupplierapply.note" id="note" rows="3" cols="60"/>200字内</td>
	</tr>
	<c:if test="${!empty newsupplierapply.supplierID }">
		<tr>
			<th>建立者</th>
			<td>${newsupplierapply.createUser}</td>
		</tr>
		<tr>
			<th>建立时间</th>
			<td>${newsupplierapply.createDate}</td>
		</tr>
		<tr>
			<th>修改者</th>
			<td>${newsupplierapply.modifyUser}</td>
		</tr>
		<tr>
			<th>修改时间</th>
			<td>${newsupplierapply.modifyDate}</td>
		</tr>
	</c:if>
	<tr>
		<th></th>
		<td>
			<input type="button" id="saveBtn" value="送出"/>
			<input type="reset" value="重填"/>
			<c:if test="${!empty newsupplierapply.supplierID }">
				<input type="button"  id="passBtn" value="核可"/>
				<input type="button" id="noPassBtn" value="审核不通过" />			
			</c:if>		
		</td>
	</tr>
</table>
</s:form>
<div  style="height:30px" class="f-link">
	<a href="${midContextPath}/newSupplierApply/search.do">回查询页</a>
</div>
